/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package podologia.beansDB;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Hernan
 */
@Entity
@Table(name = "paciente")
@NamedQueries({@NamedQuery(name = "Paciente.findByIdPaciente", query = "SELECT p FROM Paciente p WHERE p.idPaciente = :idPaciente"), @NamedQuery(name = "Paciente.findByDeporte", query = "SELECT p FROM Paciente p WHERE p.deporte = :deporte"), @NamedQuery(name = "Paciente.findByOcupacion", query = "SELECT p FROM Paciente p WHERE p.ocupacion = :ocupacion"), @NamedQuery(name = "Paciente.findByGrupoSanquineo", query = "SELECT p FROM Paciente p WHERE p.grupoSanquineo = :grupoSanquineo"), @NamedQuery(name = "Paciente.findByEmbarazo", query = "SELECT p FROM Paciente p WHERE p.embarazo = :embarazo")})
public class Paciente implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    @Column(name = "idPaciente", nullable = false)
    private Integer idPaciente;
    @Column(name = "deporte")
    private String deporte;
    @Column(name = "ocupacion")
    private String ocupacion;
    @Column(name = "grupoSanquineo")
    private String grupoSanquineo;
    @Column(name = "embarazo")
    private String embarazo;
    @Lob
    @Column(name = "detalle")
    private String detalle;
    @JoinColumn(name = "idDiabetico", referencedColumnName = "idDiabetico")
    @ManyToOne (cascade=CascadeType.ALL)
    private Diabetico idDiabetico;
    @JoinColumn(name = "idPersona", referencedColumnName = "idPersona")
    @ManyToOne (cascade=CascadeType.ALL)
    private Persona idPersona;
    @OneToMany(cascade=CascadeType.ALL, mappedBy = "idPaciente")
    private Collection<Turno> turnoCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "paciente")
    private Collection<Antepatoxpaciente> antepatoxpacienteCollection;

    public Paciente() {
    }

    public Paciente(Integer idPaciente) {
        this.idPaciente = idPaciente;
    }

    public Integer getIdPaciente() {
        return idPaciente;
    }

    public void setIdPaciente(Integer idPaciente) {
        Integer oldIdPaciente = this.idPaciente;
        this.idPaciente = idPaciente;
        changeSupport.firePropertyChange("idPaciente", oldIdPaciente, idPaciente);
    }

    public String getDeporte() {
        return deporte;
    }

    public void setDeporte(String deporte) {
        String oldDeporte = this.deporte;
        this.deporte = deporte;
        changeSupport.firePropertyChange("deporte", oldDeporte, deporte);
    }

    public String getOcupacion() {
        return ocupacion;
    }

    public void setOcupacion(String ocupacion) {
        String oldOcupacion = this.ocupacion;
        this.ocupacion = ocupacion;
        changeSupport.firePropertyChange("ocupacion", oldOcupacion, ocupacion);
    }

    public String getGrupoSanquineo() {
        return grupoSanquineo;
    }

    public void setGrupoSanquineo(String grupoSanquineo) {
        String oldGrupoSanquineo = this.grupoSanquineo;
        this.grupoSanquineo = grupoSanquineo;
        changeSupport.firePropertyChange("grupoSanquineo", oldGrupoSanquineo, grupoSanquineo);
    }

    public String getEmbarazo() {
        return embarazo;
    }

    public void setEmbarazo(String embarazo) {
        String oldEmbarazo = this.embarazo;
        this.embarazo = embarazo;
        changeSupport.firePropertyChange("embarazo", oldEmbarazo, embarazo);
    }

    public String getDetalle() {
        return detalle;
    }

    public void setDetalle(String detalle) {
        String oldDetalle = this.detalle;
        this.detalle = detalle;
        changeSupport.firePropertyChange("detalle", oldDetalle, detalle);
    }

    public Diabetico getIdDiabetico() {
        return idDiabetico;
    }

    public void setIdDiabetico(Diabetico idDiabetico) {
        Diabetico oldIdDiabetico = this.idDiabetico;
        this.idDiabetico = idDiabetico;
        changeSupport.firePropertyChange("idDiabetico", oldIdDiabetico, idDiabetico);
    }

    public Persona getIdPersona() {
        return idPersona;
    }

    public void setIdPersona(Persona idPersona) {
        Persona oldIdPersona = this.idPersona;
        this.idPersona = idPersona;
        changeSupport.firePropertyChange("idPersona", oldIdPersona, idPersona);
    }

    public Collection<Turno> getTurnoCollection() {
        return turnoCollection;
    }

    public void setTurnoCollection(Collection<Turno> turnoCollection) {
        this.turnoCollection = turnoCollection;
    }

    public Collection<Antepatoxpaciente> getAntepatoxpacienteCollection() {
        return antepatoxpacienteCollection;
    }

    public void setAntepatoxpacienteCollection(Collection<Antepatoxpaciente> antepatoxpacienteCollection) {
        this.antepatoxpacienteCollection = antepatoxpacienteCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPaciente != null ? idPaciente.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Paciente)) {
            return false;
        }
        Paciente other = (Paciente) object;
        if ((this.idPaciente == null && other.idPaciente != null) || (this.idPaciente != null && !this.idPaciente.equals(other.idPaciente))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "podologia.beansDB.Paciente[idPaciente=" + idPaciente + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

    public String getNombreCompleto(){
        return getIdPersona().getApellido()+" "+getIdPersona().getNombre();

    }

}
